import React from "react";
import "./index.scss";
import { Button, Form, Input,message } from "antd";
import { usersLogin } from "../../api/account";
import { UserSwitchOutlined, LockOutlined } from '@ant-design/icons'
import { useNavigate } from "react-router-dom";
export default function index() {
  const navigate = useNavigate()
  const onFinish = (values) => {
    console.log("Success:", values);
    usersLogin({ password: values.password, account: values.username }).then(res => {
      let date = res.data;
      if (date.code == 1) {
        navigate("/home");
        console.log(date);
        message.success(date.msg);
      }
      else {
        message.error(date.msg)
      }
    })
  };


  return (
    <div className="bg">


      <div className="login">
        <Form
          name="basic"
          onFinish={onFinish}
        >
          <Form.Item
            name="username"
            rules={[
              {
                required: true,
                message: "请输入您的账号",
              },
            ]}
          >
            <Input placeholder="请输入账号" prefix={<UserSwitchOutlined />} />
          </Form.Item>

          <Form.Item
            name="password"
            rules={[
              {
                required: true,
                message: "请输入您的密码",
              },
            ]}
          >
            <Input.Password prefix={<LockOutlined />} placeholder="请输入密码" />
          </Form.Item>


          <Form.Item >
            <Button block type="primary" htmlType="submit">
              登录
            </Button>
          </Form.Item>
        </Form>
      </div>
    </div>
  );
}
